package com.giw.project.graph;

import java.io.IOException;


import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import com.giw.project.exception_manager.UncheckedException;

public class GraphGeneratorReducer extends Reducer<Text, Text, Text, Text>{
	protected void reduce(Text key, Iterable<Text> values, Context context) 
	throws IOException, InterruptedException {
		StringBuffer buffer = new StringBuffer();
		for(Text value:values){
			buffer.append(value);
			buffer.append(",");	
		}
		String finalGraphDescription=buffer.toString();
		finalGraphDescription=finalGraphDescription.substring(0,finalGraphDescription.length()-1);
		finalGraphDescription=finalGraphDescription.concat(".");
		try{
			context.write(key, new Text(finalGraphDescription));
		}
		catch(IOException e){
			throw new UncheckedException("Error while trying the reduce operation.\nMeesage:"+e.getMessage());
		}
		catch(InterruptedException e){
			throw new UncheckedException("Error while trying the reduce operation.\nMeesage:"+e.getMessage());
		}
	}

}
